package com.dcy.db.base.controller;

import com.dcy.common.api.IErrorCode;
import com.dcy.common.constant.Constant;
import com.dcy.common.model.R;
import org.apache.dubbo.rpc.RpcContext;

/**
 * @Author：dcy
 * @Description:
 * @Date: 2021/4/15 15:02
 */
public class RBaseController {

    protected <T> R<T> success(T obj) {
        return R.success(obj);
    }

    protected <T> R<T> error(String msg) {
        return R.error(msg);
    }

    protected <T> R<T> error(IErrorCode errorCode, T obj) {
        return R.error(errorCode);
    }

    protected <T> R<T> restResult(IErrorCode errorCode, T data) {
        return R.restResult(errorCode, data);
    }

    /**
     * 获取用户id
     */
    protected String getUserId() {
        return RpcContext.getContext().getAttachment(Constant.USER_ID);
    }

    /**
     * 获取用户名称
     */
    protected String getUsername() {
        return RpcContext.getContext().getAttachment(Constant.USER_NAME);
    }
}
